package com.adcc.loadsheet.billing.security;

import com.adcc.loadsheet.billing.vo.permission.PermissionEntityVO;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

import java.util.*;

public class UserInfo {

    private String username;

    private String password;

    private boolean isSuperAdmin;

    // 用户类型（key：公司id，value：用户类型1,2,3）
    private Map<Integer, String> userType = Maps.newHashMap();

    //合同用户简称
    private String contractUserAbbrev;

    //是否是合同用户
    private boolean isContractUser;

    //角色
    private String[] roles;

    //角色权限全集
    private Set<String> roleAndPermission = Sets.newConcurrentHashSet();


    // ------------------------------------------------------

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Map<Integer, String> getUserType() {
        return userType;
    }

    public void setUserType(Map<Integer, String> userType) {
        this.userType = userType;
    }

    public boolean isSuperAdmin() {
        return isSuperAdmin;
    }

    public void setSuperAdmin(boolean superAdmin) {
        isSuperAdmin = superAdmin;
    }

    public Set<String> getRoleAndPermission() {
        return roleAndPermission;
    }

    public void setRoleAndPermission(Set<String> roleAndPermission) {
        this.roleAndPermission = roleAndPermission;
    }

    public String[] getRoles() {
        return roles;
    }

    public void setRoles(String[] roles) {
        this.roles = roles;
    }

    public String getContractUserAbbrev() {
        return contractUserAbbrev;
    }

    public void setContractUserAbbrev(String contractUserAbbrev) {
        this.contractUserAbbrev = contractUserAbbrev;
    }

    public boolean isContractUser() {
        return isContractUser;
    }

    public void setContractUser(boolean isContractUser) {
        this.isContractUser = isContractUser;
    }

    // ------------------------------------------------------
    //创建用户
    public UserInfo setUserVO(String username, boolean isSuperUser,boolean isContractUser,String contractUserAbbrev,List<PermissionEntityVO> permissionEntityVOList) {
        UserInfo uservo = new UserInfo();
        uservo.setUsername(username);
        uservo.setSuperAdmin(isSuperUser);
        uservo.setContractUser(isContractUser);
        uservo.setUserType(userType);
        uservo.setContractUserAbbrev(contractUserAbbrev);

        Set<String> permissions = Sets.newConcurrentHashSet();
        permissions.add("BillingManage");
        for(PermissionEntityVO permissionEntityVO : permissionEntityVOList){
            permissions.add(permissionEntityVO.getPermissionMark());
        }
        uservo.setRoleAndPermission(permissions);

        return uservo;
    }
}